package io.github.rascaler.dcenter.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

/**
 * @ClassName Candlestick
 * @Description TODO
 * @Author wurenqing
 * @Date 2023-11-23 11:06
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CandlestickRank {

    private Long barDate;
    private BigDecimal open;
    private BigDecimal high;
    private BigDecimal low;
    private BigDecimal close;
    private BigDecimal volume;
    private BigDecimal amount;
    private Integer rankUp;
    private Integer rankDown;

    public String toCsv(String key, String split) {
        StringBuilder builder = new StringBuilder();
        builder.append(key).append(split)
                .append(barDate).append(split)
                .append(open).append(split)
                .append(high).append(split)
                .append(low).append(split)
                .append(close).append(split)
                .append(volume).append(split)
                .append(amount).append("\n");
        return builder.toString();
    }

    public static Object[] parseCsv(String line, String split) {
        CandlestickRank candlestick = new CandlestickRank();
        String[] val = line.split(split);
        candlestick.setBarDate(Long.parseLong(val[1]));
        candlestick.setOpen(new BigDecimal(val[2]));
        candlestick.setHigh(new BigDecimal(val[3]));
        candlestick.setLow(new BigDecimal(val[4]));
        candlestick.setClose(new BigDecimal(val[5]));
        candlestick.setVolume(new BigDecimal(val[6]));
        candlestick.setAmount(new BigDecimal(val[7]));
        return new Object[]{val[0], candlestick};
    }



}